package com.wh.custom.controller;

import com.wh.custom.pojo.CustomRegion;
import com.wh.custom.service.impl.CustomRegionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
获取省市区
 */
@RestController
@RequestMapping("/region")
public class CustomRegionController {

    @Autowired
    private CustomRegionServiceImpl customRegionService;

    // 获取所有省市区信息
    @GetMapping("/all")
    public List<CustomRegion> getAllRegions(@RequestParam(required = false, defaultValue = "0") Long parentId) {
        System.err.println(customRegionService.findByParentId(parentId));
        return customRegionService.findByParentId(parentId);
    }

    // 根据省份获取市级信息
    @GetMapping("/cities/{provinceId}")
    public List<CustomRegion> getCitiesByProvince(@PathVariable Long provinceId) {
        System.err.println(customRegionService.findByParentId(provinceId));
        return customRegionService.findByParentId(provinceId);
    }

    // 根据市级获取区县级信息
    @GetMapping("/districts/{cityId}")
    public List<CustomRegion> getDistrictsByCity(@PathVariable Long cityId) {
        System.err.println(customRegionService.findByParentId(cityId));
        return customRegionService.findByParentId(cityId);
    }


}
